/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       sound.h
 * Author:     karooolek
 * Created on: 2009-03-24
 *
 **********************************************************************************************************************/

#ifndef SOUND_H_
#define SOUND_H_

#include "../common.h"
#include <AL/al.h>

namespace mGameEngine
{
namespace Audio
{

/**
 * Sound resource.
 * Each sound can have multiple channels, but only mono sounds
 * can be attached to positional sound sources.
 */
class Sound
{
protected:
    /**
     * Sound data buffer.
     */
    uint8 *_data;

    /**
     * Sound length. Number of samples for one channel.
     */
    uint _length;

    /**
     * Sampling rate.
     */
    uint _sampleRate;

    /**
     * Number of sound channels.
     */
    uint8 _channels;

    /**
     * Bits per sound sample.
     */
    uint8 _bps;


public:
    uint buffer;

public:
    /**
     * Create empty sound.
     */
    Sound();

    /**
     * Create sound from data buffer.
     * @param data data buffer.
     * @param length sound length.
     * @param sampleRate sampling rate.
     * @param channels number of sound channels
     * @param bps bits per sound sample.
     */
    Sound(const uint8 *data, uint length,
            uint sampleRate, uint8 channels, uint8 bps);

    /**
     * Destroy sound.
     */
    virtual ~Sound();

    /**
     * Get sound data buffer.
     * @return sound data buffer
     */
    const uint8 *getData() const
    {
        return _data;
    }

    /**
     * Set sound data.
     * @param data data buffer
     * @param length sound length.
     * @param sampleRate sampling rate.
     * @param channels number of sound channels
     * @param bps bits per sound sample
     */
    void setData(const uint8 *data, uint length,
                    uint sampleRate,  uint8 channels, uint8 bps);

    /**
     * Get sound length.
     * @return sound length.
     */
    uint getLength() const
    {
        return _length;
    }

    /**
     * Get sound samplig rate.
     * @return sound sampling rate.
     */
    uint getSamplingRate() const
    {
        return _sampleRate;
    }

    /**
     * Get number of sound channels.
     * @return number of sound channels.
     */
    uint8 getNumberOfChannels() const
    {
        return _channels;
    }

    /**
     * Get bits per sound sample.
     * @return bits per sound sample.
     */
    uint8 getBitsPerSoundSample() const
    {
        return _bps;
    }

    /**
     * Get specified sample data.
     * @param sample sample number.
     * @param channel channel number.
     * @return specified sample data or NULL if sample is not in sound.
     */
    virtual const uint8 *getDataAt(uint sample, uint8 channel) const;

    /**
     * Set specified sample data.
     * @param data sample data to set.
     * @param sample sample number.
     * @param channel channel number.
     */
    virtual void setDataAt(const uint8 *data, uint sample, uint8 channel);
};

}
}

#endif // SOUND_H_
